package com.ruoyi.web.controller.course;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.course.domain.SysMaterial;
import com.ruoyi.course.service.ISysMaterialService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 资料Controller
 * 
 * @author YJF
 * @date 2023-05-11
 */
@RestController
@RequestMapping("/course/material")
public class SysMaterialController extends BaseController
{
    @Autowired
    private ISysMaterialService sysMaterialService;

    /**
     * 查询资料列表
     */
    @PreAuthorize("@ss.hasPermi('course:material:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysMaterial sysMaterial)
    {
        startPage();
        List<SysMaterial> list = sysMaterialService.selectSysMaterialList(sysMaterial);
        return getDataTable(list);
    }

    /**
     * 获取资料详细信息
     */
    @PreAuthorize("@ss.hasPermi('course:material:query')")
    @GetMapping(value = "/{materialId}")
    public AjaxResult getInfo(@PathVariable("materialId") Long materialId)
    {
        return AjaxResult.success(sysMaterialService.selectSysMaterialByMaterialId(materialId));
    }

    /**
     * 新增资料
     */
    @PreAuthorize("@ss.hasPermi('course:material:add')")
    @Log(title = "资料", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysMaterial sysMaterial)
    {
        return toAjax(sysMaterialService.insertSysMaterial(sysMaterial));
    }

    /**
     * 修改资料
     */
    @PreAuthorize("@ss.hasPermi('course:material:edit')")
    @Log(title = "资料", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysMaterial sysMaterial)
    {
        return toAjax(sysMaterialService.updateSysMaterial(sysMaterial));
    }

    /**
     * 删除资料
     */
    @PreAuthorize("@ss.hasPermi('course:material:remove')")
    @Log(title = "资料", businessType = BusinessType.DELETE)
	@DeleteMapping("/{materialIds}")
    public AjaxResult remove(@PathVariable Long[] materialIds)
    {
        return toAjax(sysMaterialService.deleteSysMaterialByMaterialIds(materialIds));
    }
}
